package Arrays101.Day05;

public class Day05_1 {
    public static void main(String[] args) {
        int[] ints = replaceElements(new int[]{400});
        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i]);
        }

    }

    /**
     * Replace Elements with Greatest Element on Right Side
     *
     * Given an array arr, replace every element in
     * that array with the greatest element among the elements to its right,
     * and replace the last element with -1.
     * After doing so, return the array.
     * @param arr
     * @return
     */
    public static int[] replaceElements(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            if (arr.length==1){
                arr[i]=-1;
            }
            int max=0;
            for (int j = i+1; j < arr.length; j++) {
                if (max<arr[j]){
                    max=arr[j];
                }
            }
            arr[i]=max;
            if (i==arr.length-1){
                arr[i]=-1;
            }
        }
        return arr;

    }
}
